How to get this .php code from my theme into my plugin?

You don’t, what you’ve modified is a template file, those don’t go in plugins.

Instead, create a child theme and copy this file into that theme. WordPress will preferentially load templates from the child theme, falling back to the original parent theme. This way any modifications you make in the child theme will overwrite the parent, and if the parent is updated no changes are lost