CGI programming presents various challenges for the programmer. It's segmented user interaction and limited text-input abilities present hoops which the programmer must jump through. However, because of the ubiquitous ability for people to use resources written using the CGI, it's benefits often far outweight these drawbacks.
Observe the following key points when writing CGI programs:
Carefully design the user-interaction through forms, preserving data from earlier stages of processing to where it's needed in later stages.
Take security and file access into account at all stages of processing. Make sure that the CGI programs can read the data files necessary to perform their function.
Perform error-checking on all form data input. Make sure that whatever type of data you expect to be in a field is actually there, and that all fields are filled out as appropriate. If this is not the case, inform the user and stop processing.
Use file locking to ensure that CGI programs don't squash each other while accessing data files.
Use pre-written libraries to make the tedious parts of CGI programming easier.
Keeping these points in mind will help you to write correct, error-free and useful CGI programs.