Does Apache require special settings to run a command?
The problem has been solved. Basically Apache did not have permission to write into the folder. Steps to solve the issue included:


ls -la cgi-bin to check the permissions of my cgi-bin folder.
Give the _www group ownership of cgi-bin and give the group write permissions: chgrp -R _www cgi-bin &amp;&amp; chmod g+w cgi-bin.
In addition, I added my User to the group _www so I would not have to authenticate myself every time I added a file in the cgi-bin folder. 
sudo dseditgroup -o edit -a ikr -t user _www was used to do Step 3 (ikr has to be replaced with the username to be added)