Added close file in WriteYaml

This will fail on windows if the file is still open when renaming
Please comment here about *why* we're closing here, so someone doesn't revert the change later, thinking it's unnecessary.