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.