explicitly close files (closes #23090)

Patch by Brian Kearns.