add file arg to showtraceback

allows capture of rendered tracebacks, matching things like `traceback.print_traceback`

I originally added this in #6394, but it didn't turn out to be necessary. I still think it's a good idea, so I gave it its own PR.