The following statement in the ReportDesign.afterFactory method closes the file.
Using this method flushes all the buffers and ensures that all method output appears in the file.
To provide the ReportDesign.afterFactory code, select the top line of the outline and select the afterFactory method on the code page.