File stream closing

One of the tests intermittently fails. It seems to be because two tests are opening the same file, and this is causing the second test to sometimes receive an unexpected `close` event from the stream. This change manually closes the underlying streams in a predictable manner.
Done