add freopen() with tests

it works with plain_wrapper only, though
patch by Evgeniy Makhrov

particularly useful to redirect all the output to a file:

$str = "data\n";
$file = "stdout.log";
freopen($file, "a", STDOUT);
echo $str; //you won't see this line