In the future, I recommend using temp files like the following, which avoids the need to call `close`:

```ruby
Tempfile.open("validate_cmd") do |tmpfile|
  tmpfile.write(content)
end
```

This will ensure the file is always closed, even if there's exceptional behavior after opening the file.