Fix UTF-8 encoding failure when creating CSV files

Fixes #163