[LIT] Fix quadratic behavior collecting process output (#222419)
Repeatedly appending to a string is quadratic.
This makes lit very slow when tests emit large amounts of output.
Fixing this speeds up one Swift compiler test by 36x (from 720s down to
20s).