Added safe handling of files - if a file already exists, new file with "-n" prefix is created, where n is the next available number