New empty cells (fresh variables) are created for any unbound variable in the original term:
?- length(G,3),duplicate_term(G,H),G=[_,hello,_]. G = [_23512,hello,_23524], H = [_24218,_24224,_24230].
duplicate_term/2 can deal with cyclic structures:
?-
A=[1,K,3|A],B=[a,b|A],
cyclic_term(A),
duplicate_term(B,BB),nth0(3,BB,foo).
A = [1, K, 3|A],
B = [a, b|A], % B = [a,b,1,K,3,1,K,3,1,K,3,....]
BB = [a, b|_S1], % where % BB as B but with the copy of K bound to 'foo'
_S1 = [1, foo, 3|_S1].