Use appropriate mode when writing binary file