in reply to howto redirect STDOUT to $socket

use mode >& instead of > to (re)open STDOUT:
open STDOUT, '>&', $ns or die "Nope: $!\n";