How did working conditions in factories lead to the formation of labor unions?

They wanted better working conditions.