avoiding encoding issues by writing in binary mode