Thank you for you quick response. Specifying the file format type resolved the issue.
But now I am getting Nullpointerexception in following code part
// get the template worksheet for the leaf node provided.
Worksheet templateWorksheet = templateWorkbook.getWorksheets().getSheet(leafNode.getTabType());
// add a new worksheet in the target workbook.
Worksheet targetWorksheet = targetWorkbook.getWorksheets().addSheet();
// copy the contents of template worksheet to added worksheet.
// change the name of added worksheet.
// get all the named ranges from the worksheet.
NamedRange namedRanges = targetWorksheet.getNamedRanges();
I am getting namedRanges as null, in the saved targetWorksheet.xlsx I am not getting named range which is there in templateworksheet.