Fixes unterminated line at end of output file problem.
------------------------------------------------------

Output an unterminated output line on closing the output file.
Previously this unterminated data would be carried over to the
next output file, or cause a crash if there was none.