Can anyone tell me why this bit of simpleXML code is writing 2 entries to my XML file instead of just 1?

<?php
// ----------BUILD XML FILE WITH DATA ENTERED INTO FORM----------

$filename = "inventory.xml";

// Load the vehicle entries from the XML file

$xml = simplexml_load_file($filename);

// Add the new entry as a child node
$entry = $xml->addChild("entry");
$entry->addChild("img_txt", $_POST["img_txt"]);
$entry->addChild("title", stripslashes($_POST["title"]));
$entry->addChild("description", stripslashes($_POST["description"]));
$entry->addChild("price", stripslashes($_POST["price"]));
$entry->addChild("vin", stripslashes($_POST["vin"]));

// Write the entire entry to the file
$file = fopen($filename, 'w');
fwrite($file, $xml->asXML());
fclose($file);

echo("XML file written!" . "<br/><br/>");



The user fills out a multipart (an image is uploaded to server) form here:

http://randdtrucks.com/inc/upload/

which executes the code you saw earlier, and this code writes it all into HTML on another page

$filename = "inventory.xml";

// Load the vehicle entries from the XML file

$xml = simplexml_load_file($filename);

$entry = $xml->entry;
//$numEntries = count($entry);
//echo $numEntries;

foreach($entry as $node) {
echo '<li>';
echo '<span class="title">' . $node->title . '</span>';
echo '<img class="row2" src="http://randdtrucks.com/photos/' . $node->img_txt . '">';
echo '<p class="row2">' . $node->description . '</p>';
echo '<p class="price">' . $node->price . '</p>';
echo '<a href="http://www.carfax.com/VehicleHistory/p/Report.cfx?partner=DVW_1&vin=';
echo $node->vin . '">';
echo '<img src="http://www.carfaxonline.com/img/new_blk_logo.gif" class="cfimage" /></a></li>';
}


Where am i going wrong? I fill out the form once and only once, but I still end up with 2 xml entries like this:


<?xml version="1.0" encoding="utf-8"?>
<entries>
<entry>xml data here</entry>
<entry>xml data here</entry>
</entries>