Write to file

add SORT_BY parameter
write to file with utf-8 encoding