I'm not sure what you mean by 'calling the script in an html image tag'...
So, as far as how to fix that... Well, based on what you originally needed, I kindly suggest that it's not (very) broken.
You wanted a utility which would list all of the images of types .jpg, .gif or *.png within a directory, which it accomplishes.
Then you wanted a random image selected from that list, which it also does.
Perhaps if we take a few steps backwards and try some simple tests, like:
Select an image from the directory '/home/puremadnezz/images/' and 'manually' create the image tag within your script. This will verify that the webserver can use images from that directory within pages...
See if that works; if it does, post the <img /> tag that you're 'manually' writing into your script, and we'll take it from there...