Fix occasional UnicodeEncodeError in non-script output