An electromagnet is a temporary magnet in which a magnetic field is produced by passing electricity through a magnetic material. It shows all the properties of an ordinary magnet until the electric current is removed.
So an electromagnet cannot be used for separating plastic bags from a garbage heap because plastic bags are non-magnetic materials and an electromagnet can only be used to separate magnetic materials.
So by using an electromagnet, scrap iron can be separated from the heap, as it is a magnetic material.