in reply to duplicate entry error

You probably had a primary/unique key set on the filename. If you want to overwrite it, just add a delete SQL before you do the insert. If you want custom error messages, you need to turn off automatic error handling with something like this -
my $dbh = DBI->connect( blah, blah, {PrintError => 0, RaiseError => 0} ) or die "message"; ... $sth->execute() or die "print your own error message here."