Move write_atomic to utils