You can close the file immediately after writing the content. Then open it whenever you want again close it.
--open new file and write
var file = "D:\\dump.txt";
var outfile = system.openFileForOutput(file);
outfile.newLine ();
outfile.write("Report")
outfile.newLine ();
outfile.close ();
--append content to the previously created file
var file = "D:\\dump.txt";
var outfile = system.openFileForAppend(file);
outfile.newLine ();
outfile.write("Report")
outfile.newLine ();
outfile.close ();
Also there are some google groups for TDI related doubt. https://groups.google.com/forum/#!forum/ibm.software.network.directory-integrator