Could it be that the * is giving problems? What if you try to set secure with some content that does not contain asterisk? In bash, * is expanded. You could also try secure='*(rw,..)' (single quote), so that it does not expand.
Just a guess but your script may be in DOS format that you're actually trying to write output to a.txt\r instead. Try to run one of the following to your code and try again:
a.txt? Can you show output ofls -l a.txt?echo "$path" >> a.txt*is giving problems? What if you try to setsecurewith some content that does not contain asterisk? In bash,*is expanded. You could also trysecure='*(rw,..)'(single quote), so that it does not expand.