use binary mode when writing file.
Merge pull request #1364 from koron/write-in-binary-mode

use binary mode when writing file.