Close the file descriptor in has_yaml_header?

Previous method caused a problem where the calling Dir.chdir to get the next
directory's entries would cause the infamous 'Too many open files - getcwd'
error. Fixes #2279.