When you run sudo, you actually execute the commands as the root user. You might end up messing up the permissions so that root owns the files. Thus, when you run sudo, it just works (root can write to these directories). You need coolmego to own these files. For instance:
sudo chown coolmego /home/coolmego/coolmego/cprograms/
chmod 700 /home/coolmego/coolmego/cprograms/
source
share