improve encoding when file writing