Fixing utf8 compatibility of file writes
fixing handling of file data for binary vs string