Looks like you've got an extra bracket after the if clause, and could you maybe throw some code tags around the code? Variable width font makes it difficult to read code, at least for me.
So it looks like right before you're loading it with IM you're assigning $fname from the @ARGV array (in the else). Did you check what was in @ARGV? What is the calling syntax?
Sorry about the smilies, I'm feeling giddy right now for some reason.