New to PHP and STUCK!

Im using a flash music player that gets it’s playlist from an XML file. Now I want to be able to add and remove songs from this playlist. I’m using a PHP script to do this, which works 100% to remove specified tracks, but as soon as I try to add a track, it remove all previous tracks and only display the newly added track.

Can someone PLEASE look at the code for me and tell me whats wrong with it?