I have ArcGIS Pro 2.5 right now, and there is a problem with having two different results when I execute code from the Python window vs. executing from a script. The script version will not respect the selection when I copy one geodatabase class to a new one.
I have a point table called "spatial_join1" with 222 points. I use arcpy.management.SelectLayerByAttribute to select 5 records. That command works the same in the Python window and in the script. I then use arcpy.onversion.FeatureClassToFeatureClass() to save those 5 records as a new layer. If I execute that command in the Python window, I get 5 features in the new layer. When I run the script with the same command, I get the full 222 record set.
(this is the Python window version)

(this is the script version).
Am I using the wrong tool, or do I need a line in my script file to tell it to respect the selection?
Thanks for the help--