Hello Robert,
You said that the script worked when you ran it with sieve-test, proabably as root user, but not when you sent an e-mail with sendmail, which I guess would run it as the dovecot user (probably vmail as you said you changed the ownership of the e-mail to vmail:mail ?)
You forgot to show us the file permissions on the script and the folder containing it. A namei -l on the whole path can show if dovecot can reach it.
Example :
root@messagerie-secours[10.10.10.20] ~ # namei -l /var/vmail/mailfilters/spam.svbin f: /var/vmail/mailfilters/spam.svbin drwxr-xr-x root root / drwxr-xr-x root root var drwxr-xr-x vmail vmail vmail drwxr-xr-x root root mailfilters -rw-r--r-- vmail vmail spam.svbin root@messagerie-secours[10.10.10.20] ~ #
-- Yassine.