Handle file output and stdout end cases separately

This avoids errors when the output stream is `process.stdin`.
Merge pull request #4 from Automattic/update/output

Use write() instead of end() on the output stream