Made the vendored NamedTemporaryFile work as a context manager. Refs #22680.

This fixes a regression on Windows introduced by b7de5f5.

Thanks Tim Graham for the report and review.