The statistics file update does not check for write errors correctly
as stdio files are normally buffered. This means that data can be
written to the stdio buffer but not written out until fclose().
Hence, it is imperative that the fclose() return value is also
checked.
If either fprintf() or fclose() fail, clean up the temporary file,
rather than littering the filesystem with needless temporary files.