write index to file.