Closing files when writing is finished.