Improved file name generation algorithm