Added close file in WriteYaml

This will fail on windows if the file is still open when renaming

gofmt