Fix jruby warning when capture calls unlink on an open tempfile

Jruby cannot unlink a tempfile unless it is closed first.
Merge pull request #11725 from atambo/jruby_capture_unlink

Fix jruby warning when capture calls unlink on an open tempfile