Obviously, gold is an element that exists in many places in our universe and beyond. The earth had to have some when it was formed and my guess is that at least some came later as the earth was bombarded by countless projectiles of varying size and shape.
My experience and knowledge is very limited but one crystalline nugget I found not far from Sulfur, Nevada made me think that gold was somehow chemically leached out of low grade ore or soil only to reform as, well, see the nugget photo below.
Reading this article added to my intrigue...
Iridium in undersea crater confirms asteroid wiped out the dinosaurs
"A separate study of the cores done in 2019 reveals that the crater rock has been depleted of sulphur when compared to surrounding limestone. This suggests that the impact blew large amounts of sulphur into the air, where it would have contributed to the cooling and then fallen as acid rain – making the situation on the ground even worse."