Fix jruby warning when capture calls unlink on an open tempfile

jruby cannot unlink a tempfile unless it is closed first.

See http://jira.codehaus.org/browse/JRUBY-6688 for jruby details.

#11700

cc: @arunagw, @rafaelfranca