Here's how I would design this:
- Check for the existence of the cfg file
- If it exists, read values out of it into a hash (field name => value)
- Otherwise, initialize the hash with default values
- Build the form from the hash -- you'll want to change the value= bits of your form to refer to the hash values, instead of having the data hardcoded
That should get you started. Good luck.