I'm a little confused about what you are trying to do here. If it's your intention to process the SSI-directives while your CGI-script reads the file and prints it to STDOUT, it won't work.
The processing of the SSI directives will be done by the webserver only because it detects the file-extension .shtml. Since the server now processes your CGI script (ending in .cgi or .pl), it does not know that it is supposed to interpret the directives...