safe write app_process

write a tmp file, then rename to the actual file.