delete index file before writing to it (if change)

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