Fix: write to file should handle bytes

The previous code uses 'r' which I believe is a typo
Merge pull request #7 from yegle/fix-output-to-file

Fix: write to file should handle bytes