$nick is the person who triggers the script. You were supposed to use $2 instead. A little trigger protection is needed so the client that runs the code doesn't get spammed:
on *:text:*:*:{
tokenize 32 $strip($1-)
if ($1 == !address) && (!%f) && ($2 ison #) {
inc -u3 %f | msg $iif(#,#,$nick) $address($2,0) is $2's hostmask.
}
}
If you're gonna use * instead of the # in your text event, you should use $iif(#,#,$nick) to make it work for either the channel or PM. And as napa said, it's best you strip out control codes.