Well, it's a start, but if I'm reading your code correctly (and I might not be, 'cause it's late here ), I believe that the error is generated as a result of the following code:
$f = fopen($events["path"]."/tmp".$tempfolder."/preview.xml","w");
and, from that, I suspect the problem lies in the code that assigns $events, which you did not include. Basically, it looks like $events["path"]."/tmp".$tempfolder." evaluates to a (partial) url, and the code that sets that up is not here.
You may not need to "cURL" it at all, if you can modify the appropriate strings/variables to produce a path on the server rather than an "http://" url. I'd start looking at the problem from that standpoint, and using that approach, before trying to "cURL" the whole thing, but that's just me. There are others far more expert at PHP than me on the forum, and maybe one of them will have a better suggestion.
It also helps greatly if you provide the whole, rather than a truncated, error message - without the whole error message, we are kinda "debugging" in the dark.