added UTF-8 encoding to file writing