Clean up tempfiles from output stream

Fixes #57, with a test!