DBI wouldn't do what you describe, unless you have duplicate rows in your tables or something.
Perhaps the problem is that you are always appending to $websites and not resetting it? Try putting
Or, make $websites a lexically scoped (my) variable,
in your outer while loop (before you start the inner while
loop). That will ensure that the variable is newly created
for every iteration.