Fixed the update function to copy contents to a new file and
then rename that to the original filename when successful.