Proper output file close

Fix the bug where file might not be closed properly and cause ginkgo tests to fail