Hello,
What is the error you are getting while running the script?
In case you want to run it on the same Plesk server it might be easier to use CLI, the commands for retrieving list of email addresses and creating new email address are available via plesk bin mail. More information can be found...