I think Apache is not running the CGI but instead returning the contents of the CGI as the result. So what you are seeing is the machine code, which also includes all of the error messages that can be returned. The Out of Memory error is just one of the errors displayed.
I think the instructions James Cook posted in 2017 are no longer complete. I’m not sure if it had happened by 10.12, but at some point Apple changed the default Apache configuration to disabled CGI plugins. Fixing this requires editing the Apache configuration file (httpd.conf), which is tricky, though BBEdit can do it.
Ok, I did a forum search (for httpd.conf), and it looks like you (Robert) have run into this exact problem before, three years ago. And Apple made the change in 10.10, so that is almost certainly the problem you are encountering today.