It's failing, due to the fact that mIRC is evaluating the | character as a pipe (command separator).

Include the n switch with the w in the $read to prevent this.