Fixed output file not being closed at end of output.