Yes, you need to split the filename and extension, then generate the unique filenames then put the extension back on.
text_to_url doesn't care about extensions since it just generates a unique URL which doesn' need one, so reusing for this purpose requires some extra logic.