perl module error

Hi

I am working on XMLDiff utility which is working only thing which is bug in this utility is that i used Excel file as the output file so that user can perform some operations on it ... now what i am doing is i am using Spreadsheet::Writeexcel module and its giving me problems ...

flow of my code logic :

-> create Excel object before main so it can be accessed in entire prog.
-> validate args 
-> validate XML files given
-> compare them 
-> print Difference in excel file

now problem is even when args are wrong i create excel ( empty ) file and i 
can not remove that file because it throws error as file in use. if i do close() on excel 
sheet nothing gets printed to file even when proper inputs are given


my ($General,$AddFormat,$DelFormat,$Heading) = "" ;

my ($workbook,$worksheet) ; 

   ## CREATING EXCEL OBJECT
   
$workbook = Spreadsheet::WriteExcel->new($file);
$workbook->set_properties(
      title    => 'XML difference file',
      comments => 'Created with Perl and Spreadsheet::WriteExcel'
   );
   
$worksheet = $workbook->add_worksheet('XML difference');
   
$AddFormat = $workbook->add_format( align => 'left' , color => 'green' );
$DelFormat = $workbook->add_format( align => 'left' , color => 'red');
$Heading   = $workbook->add_format( align => 'center', bold => 1);
$General   = $workbook->add_format( align => 'left' , color => 'blue');
   
$worksheet->add_write_handler(qr[\w], \&store_string_widths);

## if i dont put excel code here nothing gets printed in excel sheet
sub main ()
{
      # Validate all arguments
   &ValidateArgs ;

      # if args are wrong 
   $workbook->close() ;  # nothing works so where should i put excel object creation part ?
   unlink "$file" ;             

      # Check if its valid XML files just by looking at the extension.
      # 
   &IsValidXML("$oldfile") ;
   &IsValidXML("$newfile") ;
   
      # print Header in excel file
   &PrintHeader ;
   
      # Compare Both the XML files 
   &CompareXML("$oldfile","$newfile") ;
      
      # Display Final Information 
   &DisplayInfo ; 
}
main ;

got this thing working ... i forgot to close the excel object in script.