use writeFileAtomic instead of fs.writeFile fixes #6163