writing index to files