The fact Ansem knew how Riku got into Sora's dreams is actually a point for it being the Ansem inside of Riku. Why? Because Xehanort didn't know how Riku got into Sora's dreams. The very first thing Young Xehanort says to Riku is demanding to know how it was Sora's dream world that Riku ended up in.
I mean you're comparing the knowledge of a character at the very beginning of the story with the knowledge of a character at the very end of it. It's not impossible for the Norts to have figured out how Riku ended up there in that time. Even in the first scene, Xehanort ends it saying things implying he is knowledgeable about it (You cannot control what you are not aware of. This wakeless sleep will be your prison. -- like clearly he knew to some extent what was happening).
In fact there is something that makes no sense if it was the time traveling Ansem. If Riku was just gonna return his own darkness to the light well then the time traveling Ansem should have no control over that, no way to prevent that, and Riku shouldn't have to fight Ansem to do that. I mean the time traveling Ansem isn't inside him it's inside his KH1 body but no Ansem there makes it sound like it's literally impossible for Riku to do the thing he's planning to do without beating Ansem first.
I mean you can also read the scene as Riku deciding to consume the darkness of Sora's nightmare. After all, as Ansem says, he is stuck in a two fold nightmare, and the darkness of that nightmare is what would trap him. When Riku makes his choice, he specifically says it as breaking the nightmare
Riku: I'm going back to the real world, and then to Sora's side.
(Ansem drops his hand)
Ansem: That...is your answer?
Riku: Yes. I know the way. Consume the darkness, return it to light.
Ansem: You can try.
Ansem stands in the way of breaking the nightmare. Riku defeats him, consumes the nightmare and turns it to light, causing him to wake in the Real World.
I mean, how does it make sense that defeating Riku's internal Ansem would cause him to leave Sora's Dream?
Heck beating up Riku wouldn't let him take over Riku that's not at ALL how possession works in this series. Not to mention again Riku is immune to darkness if that was the time traveler Ansem and he was going to attempt to posses Riku literally all that would happen is the minute he sticks his heart into Riku the kid will just lock him back up. Heck let's say this is the time traveling Ansem how exactly is accepting that Ansem going to make any sense? The time traveling Ansem already has a body, Riku's KH1 body, what is he gonna do physically fuse KH1 Riku's body with DDD Riku's body so we have a Riku within a Riku, the series seems to make it pretty clear bodies can't fuse together. If he leaves KH1 Riku's body for DDD Riku's body well that serves pretty much no purpose as that doesn't increase their vessel number it keeps it constant, the idea is to get more vessels.
I mean, I think the idea is that he's trying to convince Riku to accept the darkness, let it out, in the hopes that the darkness would overpower Riku and cause him to lose his heart/have it fall into sleep. It's the same sort of thing as the Sora scenario. YMX worked hard to turn Sora into a vessel, but YMX too already has a body. It's to make a vessel for MX to seed, not for the incarnations of Xehanort to seed themselves.
I mean if Riku is so perfectly immune to darkness than the machinations of an internal Ansem wouldn't be successful either.
After Ansem was defeated, Riku awoke in the real world.
The last part is a big clue "awoke" Riku was asleep that's why Ansem was there. Riku was pulled into his own abyss of sleep by Ansem.
This is a reach. Riku is considered sleeping the whole game because he's in the Realm of Sleep, not because Ansem pulled him into an abyss at the very end. Him waking up is just the natural progression of leaving the RoS. And again, Ansem clearly says the abyss he pulls Riku into is the darkness of Sora's nightmare, not Riku's own darkness/sleep.
Again, I'm just saying it's vague enough to be read either way. It's not like it actually matters which one someone chooses to accept, the end result is still the same.
EDIT: embarrassed how i started five paragraphs with the phrase "i mean" lol