So I made a simple script that duplicates two columns basically. When I run it from the scripteditor I get the correct result, but when I apply this script to a button suddenly it's broken...

this is the code:
function DuplicateSelectedRows() {
var spreadsheet = SpreadsheetApp.getActive();
//Insert rows
spreadsheet.getActiveSheet().insertColumns("4");
spreadsheet.getActiveSheet().insertColumns("4");
// merge cells top
spreadsheet.getRange('D2:E2').activate()
.mergeAcross();
spreadsheet.getRange('D3:E3').activate()
.mergeAcross();
//paste values in newly created rows
spreadsheet.getRange('B4:C20').copyTo(spreadsheet.getRange("D4:E20"));
spreadsheet.getRange('B3:C3').copyTo(spreadsheet.getRange("D3:E3"));
spreadsheet.getRange('B2:C2').copyTo(spreadsheet.getRange("D2:E2"));
// clear data new training
spreadsheet.getRange('B5:C20').clearContent();
};