It looks like your example was probably designed to be used with CGI. The final print statement writes the image to STDOUT, which is the console. If you run your script and redirect to a file, then double click on the output from Windows Explorer you will find it is a valid png image. For example:
GD creates an image file, it does not display it.