name_stem is a property of the Item object. selected_files is not an Item object. That is why that fails.
I think you would do better by firstly focusing on understanding what the default script does (which appears when you create a script button).