I/O exercises file_shuffler

I am having trouble on why the method is written like so in the solutions file.

def shuffle_file(filename)
base = File.basename(filename, “.*”) #Do we need these lines?
extension = File.extname(filename) # => particularly this line and the line above?
File.open("#{base}-shuffled#{extension}", “w”) do |f|
File.readlines(filename).shuffle.each do |line|
f.puts line.chomp
end
end
end

Why can we not write it like this

def file_shuffler(filename)
File.open(filename, “w”) do | f |
File.readlines(filename).shuffle.each do | line |
f.puts line.chomp
end
end
end

when the user is prompted to put a filename in, won’t they automatically put “some_file.txt” in? Isn’t the File.basename and the File.extname just taking the file and cutting the .txt off and then adding it to the file again?

OH, or are those two methods being used so we can write a new File in the directory while keeping the old file in tact?

I think I may have answered my own question.

Are there any video sources online that show great examples of working with the File class? I am searching youtube and what not but would love other resources.

Thanks everyone.