Your apache probably does not know that he should run that file as a cgi-script and does the default: print the content.
In your config, there should be a line like # AddHandler cgi-script .cgi
the # means, it's not active. Delete the #, restart your apache. What that line does is tell apache "if you see a file that ends in .cgi, execute it as a script, do not print the content, wether it sits in a cgi-bin or not".