Companies will pay a much higher hourly rate to someone they know they can part with easily if times get tough. Being an employee, especially if a union member, does nothing but set you a maximum salary limit, regardless of your ability.
Job security is a nonsensical concept in these times - there is none.
That differential also takes into account the costs that the contractor takes on. Add all the costs normally covered by a proper employer and you make up for those gains.
To suggest that job security is a non sensical concept (and that one should blindly accept indirect work) is to bring the worst of Europe’s hiring practices to the United States. That is, temporary employment promotes a harmful detachment from work.
All of that said, hiring is a business decision - nothing more.