It doesn’t work because you’re not using the code as I posted it. There’s no need to create the file or open it for writing, and the fact that you have it open for writing is why you can’t copy the file created by eggPlant to that location. The code I posted was complete – it just copies an existing file to a new location. Even if you were going to write to a file, in eggPlant you don’t have to create the file or open it for writing (you can, but it’s not necessary) – eggPlant takes care of that for you. So you can just say:
put "This is some text" into file "/path/to/myfile"
And if myfile doesn’t exist at the specified location, eggPlant will create it. You can use “put after” to append to an existing file, and “put before” to insert at the beginning of one (either will also create the file if it doesn’t exist and the location is writeable). Just “put” will erase existing contents and replace them with the specified value or create a new file if there isn’t an existing one.