Helpers for atomic file writes