Atomic file write