delete index file before writing to it

Otherwise, the file is writen in place and changes the hardlinked
ones too in older trees, therefore introduces inconsistencies in
older snapshotted trees.