You can use the Java IO library to write the contents of any variable out to a file as follows:
// write bytes out to a file
var out = new java.io.FileOutputStream('C:\\QIE\\tmp.txt', false);
var bytes = message.getBytes();
out.write(bytes);
out.close();