in reply to MD5 -- not digest::md5
A good candidate to study the potential differences of your implementation against a working implementation might be the source of Digest::Perl::MD5 which is the pure Perl implementation the wrapper Digest::MD5 falls back to, when it can't load the XS implementation.
In Section
Seekers of Perl Wisdom