in reply to Re^2: script to listen on a port & redirect to a file
in thread script to listen on a port & redirect to a file

I think he means:

[...] open my $fh, '>>', $file or die $!; while(<$new_sock>) { print $fh $_; } [...]

Alternatively, just add:

$|++

before the "$sock->accept()" call in your original script and the redirect to file will work.