Don’t re-close a closed output stream.

Fixes #1541 for 2.99.