Switch from writeFile() to writeFileSync()

Reason: writeFile() truncates instantly, emptying the file for reading.
https://github.com/joyent/node/issues/7807