use writeFileAtomic instead of fs.writeFile