Generally, $ENV{DISPLAY} isn't going to give an exact port number. The typical X11 setup assumes (TCP 6000 + $port) where $port is what you find in the variable. There are more complicated port configurations like "localhost:1.1", though, so I didn't go into lengthy discussion. Use the X11 modules which presumably do it right.