See the error I was trying something new with the language and so thought of writing the data on my local file but when i simply ran my script on localhost, i got the above error. ON digging a little deep into what could work, the simplest thing that worked for me was this.
(i use mac so all my local scripts are at var/www/) I went to the particular directly and typed in the command chmod 777 *file_name* it gave my file all the permissions it needed and I could get on with the task further.