OK, the end of it looks complete. Your copy has 4 lines added in "function fatal_error()" to do something with initializing TinyPortal. I won't be able to compare it against a stock copy of Errors.php until tonight or tomorrow, but the line count is the same in the previous copy (Errors.php~).
If the "unexpected text" (issued before all the header() stuff) was the error page about "Unable to connect", SMF should have hit the die; call and quit right after. I'm a bit puzzled as to why SMF apparently keeps running, only to go through Errors.php again. The second time around (and third, and fourth,...) Errors.php tries issuing header() calls again, and since some text has already been sent to the browser, you'll get the "cannot modify..." errors. But Errors.php should never have been called a second time!
Just for giggles, you might try replacing
die;at the end of the Errors.php file with
echo "ERROR"; exit(1); and see if it makes any difference. die is supposed to be like exit, but maybe something strange is going on. You might even try just adding () to die:
in case it's not being recognized as a system function call for some reason.