Close file handle before returning

Not closing the file handle here was causing Salt to keep a lock on the
file on Windows minions since the minion thread is long-lived.
Merge pull request #11683 from UtahDave/develop

Close file handle before returning