Reading a mailbox and sending new messages to a text file

I'm new to scripting and have been tasked with creating a script that will read a mailbox, such as /var/mail/user1, scan it for new messages, then send those new messages to another file.

It also has to be looped to run almost continuously.

Any help would be greatly appreciated

How do you know which messages are new? What if a user removes some messages? What's the point of this? (Homework? We don't like homework here.)

The Berkeley mbox format separates messages with a "From" line, containing the five letters "From", space, the sender's address (just the bare email address), two spaces, and a time stamp. There are various variations and perversions, but if your local delivery agent updates the time stamp when it writes a new message to the file, you can tell from that which messages are new. This is (reasonably) robust against the common case that a user removes a message from the mailbox while you're not looking.

If this is for "real world" requirements, I'd suggest you take a quick look at Procmail.