Switch to AtomicFile for Safe I/O. My own attempt failed miserably.