writes and reads index from/to file