The pwd command and cwd() give different results on my system (bash 4.4.20(1) on Linux).
% cd /tmp
% mkdir foo
% cd foo
% mkdir dir1
% ln -s dir1 sym1
% cd sym1
% echo PWD
/tmp/foo/sym1
% pwd
/tmp/foo/sym1
% perl -MCwd=getcwd -E'say getcwd'
/tmp/foo/dir1
% perl -MCwd=cwd -E'say cwd'
/tmp/foo/dir1
But pwd and PWD sometime give different results too.
UPDATE:The difference is pwd can be instructed to return "logical" and "physical" version, and the logical version still gets information from PWD. Cwd's documentation: "The cwd() is the most natural form for the current architecture. For most systems it is identical to `pwd` (but without the trailing line terminator)." might perhaps be improved by saying: "The cwd() is the most natural form for the current architecture. For most systems it is identical to `pwd -P` (but without the trailing line terminator).