Formaldehyde as a probe of physical conditions in dense molecular clouds