This is probably not the "prettiest way" to perhaps do this, but the TDI UserFunctions class (associated with the system object) has a writeln method with the following signature:
public void writeln(Writer w, String str)
So you could do something like
var str = "A line of text encoded as UTF-8";
The "trick" I suppose is setting up the Writer object - you'll probably need wrap some Java objects to be able to specify the encoding and do something like:
var outFile = new java.io File("c:\\dir\\outfile.txt");
var fw = new java.io BufferedWriter(new java.io OutputStreamWriter(
new java.io FileOutputStream(outFile), "UTF8"));
But there are far smarter TDI folks out there than me who may come up with something a bit more cleaner.
Anyway, give it a shot and see how it goes.