Unify write_index_file functions