you are opening many file (in linux everything is a file) but never closing it. Then you are creating "garbage" open file, because you can't use that file anymore, but it is there. And any OS give you a limit of maximum file open (file descriptor limit); in your case about 144.
when you "kill" your application, that descriptor get released, so you can use them again.
Also, because you don't check the descriptor is valid, you didn't debugged that after the 144 open it was giving error.
Solution (that does NOT check for error) is
pclose(popen("echo a > /dev/tty.usbmodem621", 'r'));