You create some random key K.
You encrypt k using the public key of the recipient, ie. e(k).
You encrypt the message using K.
You send both of those to the recipient. A cyphertext only attack can recover K from your message M. It is not then possible to recover a private key from K.
In neither case do you ever have the private key, as such it cannot ever be recovered from a core dump. In this script it seems like they are simply doing this twice, for some unknown reason.