Need to split a large data file using a Unix script

Greetings all:
I am still new to Unix environment and I need help with the following requirement.

I have a large sequential file sorted on a field (say store#) that is being split into several smaller files, one for each store. That means if there are 500 stores, there will be 500 files. This is being done using a SQR program right now. How is this done using a Unix script? Any Pseudocode will be appreciated.

In the below example, the first two records are written to a file and when there's a change in the store#, it writes to an other file. The names of the files are lgXXX where XXX is the store number (i.e, lg002, lg003 and so on).

Format of the input file:
Store# City ZIP
--------------------
002 XXX 01601 ..> written to lg002 file
002 YYY 01601 ..> written to lg002 file
003 AAA 11111 ..> written to lg003 file
004 BBB 11222 ..> written to lg004 file
:
:
:
555 XYZ 99999 ..> written to lg555 file

Thank you!
SaiK

#!/bin/ksh

while read store city zip
do
    echo "${store} ${city} ${zip}" >> "lg${store}"
done < myInputFile