I understand that a magnetic effect is produced when the spins of electrons in an object line up. But why does this phenomenon occur? Are there some materials that cause this to occur?
Because "It's complicated". The reason lies in the interaction between electron orbitals in crystals; for most materials, the optimal configuration has electrons with opposed spins so zero net magnetic moment. For some other (Iron, cobalt) some of the the external electrons prefer to stay into orbitals with parallel spin, hence magnetic moment. This is due to the specific configuration of (all) the other electrons in the crystal.
Note that the magnetic energy (interaction between the spin of two nearby electrons) is usually small compared to the (electrostatic) interaction, so happens that electrons prefer a lower energy crystals configuration with some magnetic energy left. At ambient temperature only Iron and similar are visibly magnetic. They have strong tendency to have aligned electrons. At lower temperature (low Curie temperature) many many materials show some magnetism, that was a weak effect normally masked by thermal energy.
A common model of the alignment is called "exchange interaction", where two identical electrons (with the spin in the same direction) may be energetically favored because.. because..
How exactly that happens, you ask? For me, it is a total mysterious mess. You need to understand and model where are and what are doing many electrons... Some clarification can come from some books like "Modern Magnetic materials" But be prepared, it will be made with approximate models and several 100's pages of calculations.