CH3COOH is an accepted and common form of writing the structure of acetic acid (commonly known as vinegar when diluted in water). You are right in saying the formal notation should be used - which is C2H4O2 - since it gives the reader the types of atoms and their quantities, and these two characteristics define the exact composition of the molecule, and there's nothing wrong with that.
However, the notation CH3COOH takes you one step further and tells you something about the actual structure of the molecule, since it groups together the atoms that comprise a functional group, and a very important one at that. Grouping together COOH is an accepted and convenient form of communicating to the reader: "there is a carboxylic group here", or "this molecule is actually a carboxylic acid", which is something you'd like to know when dealing with a certain substance.
To summarize, C2H4O2 can be the molecular structure for acetic acid or formate (formic ester, as mentioned in another answer). In order to avoid confusion and, more importantly, indicate that there is a carboxylic group in the molecule, it is more convenient and straightforward to note it in the formula than letting readers figure it out themselves.