You say the address receives some of the emails, so the code is working. it is compiling the email and passing it to the SMTP Server.
once passed to the SMTP Server, it is the SMTP Servers job to relay the email to the recipient.
The scenario is that is being relayed sometimes but not other times, it is the SMTP server that is not doing the relay.
As for it working on other scripts, there couple be a difference in settings, the from address could be different, you may be setting the SMTP server and port differently.
But, to get to the cause, you will need to investigate the SMTP server logs for the messages that are not being relayed.