check the path you specify to the file destination (can you write to other dirs?)
stat the directory to see the permissions
is the user your script runs under also allowed to write to that dir?
look up
umask and
mkdir
look up
chmod and
chown when you don't get through and know what you want to do -
oterhwise ask your admin
Have a nice day
All decision is left to your taste