The attachment prints out but is not stored in $attachment. @attname now holds the attachment name correctly. All that remains is figuring out how to store the attachement into a variable for later use.
You're setting $attachment to the return value of the
print() method. The perldoc for MIME:Body doesn't say anything about print() returning anything. There are other methods that look like they'll do what you want, like as_string() and as_lines().
MIME::Tools has some of the better documentation I've seen for modules, with lots of examples. You should run "perldoc MIME::Body" or look at these pages on perldoc.com: