Are you trying to write to a file located at the same server where the script is run ? Then use local file system path instead of URL. If the file has write permissions (for the user under which PHP works), you would be able to write to it.
Under *nix it could be something like this:
PHP Code:
$filetochangeOpen = fopen("/home/myfolder/file.txt", "w");
Under Windows it could be something like this:
PHP Code:
$filetochangeOpen = fopen("C:\\myfolder\\file.txt", "w");