Method invent_filename is used by method filename which returns suggested file name.
But invent_filename uses module global variable counter which is appended into returned file name. Therefore method filename is not stable as documented in Email::MIME documentation and depends on order of Email::MIME objects on which were invent_filename resp. filename called.
MIME email is tree structure and every vertex is MIME part on which can be called invent_filename method. Therefore stable implementation of invent_filename method must uniquely encode vertex in the tree. MIME email is rooted tree, so vertex can be encoded by just the path from root.