You're right, both are solutions to the Schrodinger equation for this potential. They are equivalent representations using Euler's Formula. The preference for complex exponentials vs sinusoids comes down to mathematical convenience. They are generally interchangeable.
As a rule of thumb, if the wave function is 0 outside of a bounded region of space, you probably want a sinusoid. In these scenarios, solutions are frequently standing waves, which are identical to traveling waves, waves of the form $e^{ikx}$ of the same magnitude moving at equal speeds and opposite directions. This is precisely the case for the solutions in the infinite square well. For the boundary conditions we have either $B=A$ or $B=-A$, but
$$
Ae^{ikx}+Ae^{-ikx}=2A\cos{kx}.
$$
If $B=-A$,
$$
Ae^{ikx}-Ae^{-ikx}=2iA\sin{kx}.
$$
Now, sines and cosines have known zeros. We can manipulate the argument to match the boundaries of our regions. So if the infinite square well is potential 0 from L and infinite elsewhere, we can readily choose a sine since all sines are zero at the origin and a simple formula for the other boundary point gives us our values for k. This technique would add extra work if you used just complex exponentials instead.
$Ae^{ikx}$ for any real values of k is a traveling wave, good for modeling scattering problems, say, particles incident on a finite potential well. Here the boundary conditions don't tend to allow the simple use of wave functions with equal and opposite wave numbers having the same intensity, or standing wave solutions. Consider the reflective wave function in the finite square well problem. The solution is a combination of wave functions with equal and opposite wave numbers, but the intensities are different. You can convert $\psi=e^{ikx}+Re^{-ikx}=(1+R)\cos{kx}+i(1-R)\sin{kx}$, but note the somewhat higher complexity in the representation. There's more terms to work with in the sinusoidal case.
It comes down to ease of mathematical manipulation which varies based on the problem. For bounded states, you often want to go with sinusoidals. For scattering states, you often want to go with complex exponentials instead.