Since it's a homework question, I'll give you some pointers instead of a direct answer.
A simple search on your favorite search engine with the terms How to get a list of logged on users on Linux
will give to command to retrieve a list of currently logged on users.
You can then use redirection
to save the list to a file. Redirection allows you re-direct the output of a command to one or more file descriptors, which in your case would be a text file.
Here are some links: