Why shouldn't it? A CGI script is a program like any other, besides it method of invocation and a few special environment variables set at invocation. Anything you can do from a regular script, you can do from a CGI one. Just don't take too long to send any output or the connecting browser will time out the connection.
Makeshifts last the longest.