Fix minor chance of corrupting persistence files.

Could happen if your power went down while writing the file. As it just
so happened to do for me..