in reply to Bad file descriptor error
Welcome to the wonderful world of security. The web server runs, probably, as a user with almost no system privileges at all. This is by design. If you need to have a file that both the web-server and yourself need to write to, then that can be arranged but you may need to prevail upon your system administrators to help you do it. Access Control Lists (ACLs) can be set-up in such a way that the type of access you need, to the resource you need to share, can be permitted... and an appropriate directory-location for the file can be selected. You must coordinate this with the system administration staff.