Write output file.
Cleanup