Encode template to utf-8 when writing to file