Cook replaced his Test-match opening partner Andrew Strauss, who retired from the format.
Gregory and team-mate Josh Davey took three wickets each.
Already Division One of the County Championship would be down to a two-horse race if Essex had beaten Somerset. Essex would have had three victories, the county champions Surrey two, and every other county without a victory.