Could be a bug in the library. If you email me a standalone program that produces the issue, I can try and reproduce it and help you.
note that if your mediawiki is >= v1.16 then you should not use the "upload" function, but rather the "edit" call - or directly via the "api" call. However the upload call should check your mediawiki version, and use the api directly if it can - but I could have made a mistake.
see: http://search.cpan.org/~exobuzz/MediaWiki-API-0.39/lib/MediaWiki/API.pm#Medi...
which you can use and it will handle the tokens for you for things like file upload
something like
$title = 'somefile.jpg'; $mw->edit( { action => 'upload', filename => $title, comment => 'uploaded an image', file => [ $title ], ignorewarnings => 1, bot => 1 } );
also worth noting there is the http://search.cpan.org/~lifeguard/MediaWiki-Bot-3.005002/ extension, that is a higher level interface and provides simpler function calls - might be useful for you.
Best Regards
Jools