Locality of the perimeter in Carnot groups and chain rule