I am trying to pull data from SQL, and then write it to a text file. This does that, to an extent, but it only pulls 1 from the table, which reads test:test<
If it's a text file, the tag will not be particularly useful to you, as well. You'll need to use \n to cause a newline to happen in a text file. If it was html, then we'd have a different situation.
$accounts = "$user:$pass
";
should be
$accounts .= "$user:$pass\n";
and you definitely should pull the file_put_contents out of the loop or you'll overwrite the file every time you go through the loop.