The script looks okay to me. If "stopservices" is not running you need to look at how you are calling it in the larger script.
I would add a print line just after "sub stopservices {" to make sure that it is not running. Then look into how you are calling it.