Closes and re-opens files as necessary so you can always write to a file even if you already have the maximum number of files open. Exports one function: