Yes, it matters critically. Each string is gauged for a specific pitch (E, A, D, G, B, E from low to high). Tuning pegs are arranged to match this order. Swapping strings onto incorrect pegs makes proper tuning impossible—the string tensions and speaking lengths won't correspond, resulting in:
Always install strings in their designated positions. If you've already mixed them up, remove and reinstall correctly.