This line users = user.split.join(",") is trying to split user, which is a string that only has the username of the current iteration. And because you're writing the content of users (which is just user from that iteration) in each iteration, it just appended without a space. (joining a single string means the character never gets introduced.)

For code like this, especially since it does not require either Chef's environment nor an ERB, it's easier to see what it's doing by putting it in its own script file or running with irb and then adding puts lines to debug.