Force UTF8 output if stdout of command line compiler is redirected

The typical way of using "twee" is to redirect its output to an HTML
file. However, such a redirect will use ASCII encoding unless
overriden by the PYTHONIOENCODING environment variable. Therefore it
would break if the output contains Unicode characters.

To avoid that, check whether we are outputting to a tty or to a file
and in the latter case, explictly encode as UTF8 (with BOM).