I was reviewing one shell code and I found this command written between other shell code

>filename.txt

I don't know what this command does, so I tried it on my desktop. I made one shell script and I wrote this command inside my shell script and when I ran that, I found that it doesn't do anything.
What does this >myfile.txt do??

The command > myfile.txt will just create a file or clear the file content, if any.

This command is also to attribute something to a .txt file, if there is a command before. For example, you want to create a file with the content of a folder so you can do ls -1 > myfile.txt. This will create a file with the names of your files and directories by line.

You also can use it as a logfile of your script, so instead of show the output in the screen this command save the output in a file.

script.sh > file.txt overwrites the file with the output of the script.
Whereas, script.sh >> file.txt appends text to the end of the file.

You can redirect any output from any program on the command line to a file like this. However, this only redirects STDOUT, if you want errors in the file, too, use something like script.sh > file.txt 2>&1. This sends STDERR to STDOUT, which is being written to a file.

There is no command like filename.txt. It's only an text file named as filename.

As you asked in the title

What does >filename.txt does in shell script

">" is used for redirecting the output of the command into the text file. for example if you run the below command in the terminal

ifconfig > filename.txt

then the output of command ifconfig will not display in the terminal. but a new file will create on your working directory or overwrite if the same file is present there. You can read the output of the command from the file filename.txt.