This is a jagged seam between the concepts that underpin copyright law, versus the reality of information.
Copyright law cares very much about the provenance of the work: what prior works does this work derive from? The concept only makes sense in the context of a clear traceable lineage from one work to another.
As you hint, though, that concept does not match the reality of how we create works. Nothing in the bit stream necessarily implies what prior works this bit stream derives from; and the similarity of one work to another does not necessarily imply how, or whether, one was derived from another.
So what ends up happening is that disputes arise over to what extent one work derives from another, and how we can know whether that happened; and the similarity of the works can't decide such disputes with much reliability.
Often, supporting evidence from outside the work itself needs to be found to support any particular assertion about the derivation of one work from another.
You may claim that your work Lorem does not derive from prior work Ipsum in a way that invokes a claim from Ipsum's copyright holder. What do you do if that copyright holder disagrees?
To guard against claims that your implementation of Lorem is derived from work Ipsum, you can employ the clean room design tactic:
Have Alice decide they want to implement Lorem.
Have Bob maintain no communication with Alice.
Have Bob read the implementation of Ipsum, learning its algorithms and data structures and so on.
Have Bob publish a prose description of the implementation, without including any part of Ipsum's implementation in that description.
Have Alice read that published description, and use it to implement Lorem without ever seeing Ipsum's implementation and without ever communicating directly with Bob.
Since copyright is held in fixed expressions of ideas, not the ideas themselves, this can be an effective way to insulate Alice from claims that Lorem is a derived work from Ipsum. But only if the actors clearly document the steps they took to maintain a clean separation between them as they worked, to the extent that it would hold up in a court of law against hostile copyright lawyers.