Write to a .tmp file and then File.rename into place, so a concurrent read or a mid-write crash never sees a torn file.